package com.learn.spring.aop.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author wangxing
 * @version 2020/5/10 11:58 Administrator
 */
@Component
@Aspect
public class LoggingAspect {
    @Before("execution(public * com.learn.spring.aop.aspectj.CustomerBo.addCustomer(..))")
    public void logBefore(JoinPoint joinPoint) {
        System.out.println("logBefore() is running...");
        System.out.println("hijacked :" + joinPoint.getSignature().getName());
        System.out.println("***********");
    }

    @After("execution(public * com.learn.spring.aop.aspectj.*.*(..))")
    public void logAfter(JoinPoint joinPoint) {
        System.out.println("logAfter is running...");
        System.out.println("hijacked :" + joinPoint.getSignature().getName());
        System.out.println("***********");
    }

    @AfterReturning("execution(public * com.learn.spring.aop.aspectj.*.*(..))")
    public void logAfterReturning(JoinPoint joinPoint) {
        System.out.println("logAfter is running...");
        System.out.println("hijacked :" + joinPoint.getSignature().getName());
        System.out.println("***********");
    }
    @AfterThrowing("execution(public * com.learn.spring.aop.aspectj.*.*(..))")
    public void logAfterThrowing(JoinPoint joinPoint) {
        System.out.println("logAfter is running...");
        System.out.println("hijacked :" + joinPoint.getSignature().getName());
        System.out.println("***********");
    }
    @Around("execution(public * com.learn.spring.aop.aspectj.*.*(..))")
    public void processAuthority(ProceedingJoinPoint point) throws Throwable{
        System.out.println("ANNOTATION welcome");
        System.out.println("ANNOTATION 调用类：" + point.getSignature().getDeclaringTypeName());
        System.out.println("ANNOTATION 调用类名" + point.getSignature().getDeclaringType().getSimpleName());
        point.proceed(); //调用目标方法
        System.out.println("ANNOTATION login success");
    }

}
